<?php
if(!preg_match('/\d+\.\d+\.\d+.\d+/',$_GET["ver"]) & !preg_match('/[a-z0-9]{32,32}/',$_GET["sid"]))
{
	$arr = array ('error_code'=>'-1','error_msg'=>"非法访问",'timestamp'=>time());
	echo json_encode($arr);
}
else
{
    include 'action/setting.php';
	$con = mysqli_connect($sqldatabase, $sqlusername, $sqlpassword,$sqltable);
	
	mysqli_query($con,'set names utf8'); 
    $result = mysqli_query($con,"SELECT * FROM softlist where softid='".$_GET['sid']."'");
	$ver="";
    $uid="";
	while($row = mysqli_fetch_array($result))
    {
        $ver= $row['version'];
        $uid= $row['uid'];
    }
    $result = mysqli_query($con,"SELECT * FROM softset where uid='" . $uid . "'");
    $err_z = "";
    $err_o = "";
    while ($row = mysqli_fetch_array($result)) {
        $err_z = $row['err_z'];
        $err_o =$row['err_o'];
    }
    if($_GET["ver"]==$ver)
    {
        $result = mysqli_query($con,"SELECT * FROM softlist where softid='".$_GET['sid']."'");
        $cn =0;
        $update="";
        $notice="";
        while ($row = mysqli_fetch_array($result)) {
            $cn = (int)$row["CheckNum"] + 1;
            $update = $row["up"];
            $notice = $row["notice"]; 
        }
        mysqli_query($con,"UPDATE softlist SET CheckNum = '" . $cn . "' WHERE softid = '".$_GET['sid']."'");
        if(strpos($notice,"【语录】")!=-1)
        {
            
        	$notice = str_replace("【语录】",'',$notice);
        }
        $arr = array ('error_code'=>'0','error_msg'=>$err_z,'update'=>$update,'notice'=>$notice,'timestamp'=>time());
		echo json_encode($arr);
    }
    else if($ver="")
    {
        $arr = array ('error_code'=>'-2','error_msg'=>"软件已被删除",'timestamp'=>time());
		echo json_encode($arr);
    }
    else
    {
        $result = mysqli_query($con,"SELECT * FROM softlist where softid='".$_GET['sid']."'");
        $update="";
        $notice="";
        while ($row = mysqli_fetch_array($result)) {
            $update = $row["up"];
            $notice = $row["notice"];
        }
        $arr = array ('error_code'=>'1','error_msg'=>$err_o,'update'=>$update,'notice'=>$notice,'timestamp'=>time());
		echo json_encode($arr);
    }
}
?>